# 作者: 宇
# 2025年02月22日17时10分21秒
import os


def user_openr():
    file=open('file1','r+',encoding='utf-8')
    txt=file.read()
    # print(txt)
    # file.write('今天天气很好')
    print(txt)
    file.close()

def use_openrw():
    file=open('file1','r+',encoding='utf-8')#r+光标在最前面
    num=file.write('明天是一个好天气，每天坚持学习')
    print(num)
    file.close()


def use_opena():
    file=open('file1','a',encoding='utf-8')#a光标在最后面
    file.write("Hello")

def use_openw():
    #文件不存在会创建，存在了，会被清空
    file=open('dir1/file3','w',encoding='utf-8')
    file.write("你好好")
    print(os.getcwd())

    file.close()

def use_readline():
    file=open('file1','r+',encoding='utf-8')
    while True:
        txt=file.readline()
        if  txt:

            print(txt,end='')
        else:
            break
if __name__ == '__main__':
    use_readline()